package eu.irreality.dai.gameplay.entities;

import java.awt.Color;

import eu.irreality.dai.gameplay.actions.ActionProcessor;
import eu.irreality.dai.gameplay.actions.movement.MoveEastAction;
import eu.irreality.dai.gameplay.actions.movement.MoveNorthAction;
import eu.irreality.dai.gameplay.actions.movement.MoveSouthAction;
import eu.irreality.dai.gameplay.actions.movement.MoveWestAction;
import eu.irreality.dai.gameplay.world.GameWorld;
import eu.irreality.dai.util.Roll;
import eu.irreality.dai.util.exceptions.GameException;
import eu.irreality.dai.util.exceptions.InternalErrorException;

public abstract class Humanoid extends AliveEntity
{

    public Humanoid()
    {
	super();
    }

    public Humanoid(char c, Color color)
    {
	super(c, color);
    }

    @Override
    public void update(PropertyEntry pe, GameWorld world)
    {
	if (pe.getName().equals("monster_action"))
	{
	    try
	    {
		int r = Roll.randomInt(3);
		switch (r)
		{
		case 0:
		    ActionProcessor.process(new MoveNorthAction(world, this));
		    break;
		case 1:
		    ActionProcessor.process(new MoveWestAction(world, this));
		    break;
		case 2:
		    ActionProcessor.process(new MoveEastAction(world, this));
		    break;
		case 3:
		    ActionProcessor.process(new MoveSouthAction(world, this));
		    break;
		}
	    } catch (GameException e)
	    {
		e.printStackTrace();
	    } catch (InternalErrorException e)
	    {
		e.printStackTrace();
	    }
	    setProperty("monster_action", "idle", 10);
	}
    }
}
